package com.ckr.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpSession;

/**
 * @author Shadowckr
 * @create 2022-01-14 15:50
 */

@Controller
public class LoginController {
    @RequestMapping("/user/login")
    public String login(
            @RequestParam("username") String username,
            @RequestParam("pwd") String password,
            HttpSession session,
            Model model) {
        //如果用户名和密码正确
        if ("admin".equals(username) && "123456".equals(password)) {
            session.setAttribute("LoginUser", username);
            //noinspection SpringMVCViewInspection
            return "redirect:/main.html";//重定向到 main.html页面，也就是跳转到dashboard页面
            //如果用户名或者密码不正确
        } else {
            model.addAttribute("msg", "用户名或者密码错误");//显示错误信息
            return "index";//跳转到首页
        }
    }
}
